using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace Tomahawk.Runtime.Logic
{
    /// <summary>
    /// A Pawn is an actor that can received commands from an XController object
    /// </summary>
    public abstract class XPawn : XActor
    {

        #region "Controller relationship"

        private XController controller = null;

        [XmlElement("Controller")]
        public XController Controller
        {
            get { return this.controller; }
            set { this.controller = value; }
        }

        #endregion

        #region "Command Handling"

        /// <summary>
        /// Base class for all pawn commands types
        /// </summary>
        public abstract class PawnCommand
        {
        };

        /// <summary>
        /// Receives a command from the the controller
        /// </summary>
        internal void ReceiveCommand(PawnCommand command)
        {
            this.processCommand(command);
        }

        /// <summary>
        /// Implement this to react to commands received from the controller
        /// </summary>
        protected abstract void processCommand(PawnCommand command);

        #endregion

        #region "Exceptions"

        /// <summary>
        /// To be raised when a Pawn cannot handle a certain type of command
        /// </summary>
        public class UnknownCommandException : LogicException
        {
            public UnknownCommandException(PawnCommand command)
                : base("This pawn type cannot hangle commands of type " + command.GetType().FullName, null) { }
        }
        
        #endregion

    }

}
